<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>POST请求</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="./jquery.js"></script>
</head>
<body>
  <div>
      姓名：<input type="text" id="name">
  </div>
  <div>
    年龄：<input type="text" id="age">
  </div>
  <button onclick="submit()">发送</button>
  <script>
    function submit() {
      let data = {
        name: document.getElementById('name').value,
        age: document.getElementById('age').value
      };
      $.ajax({
        url: '/json',
        type: 'POST',
        data: data,
        success: function(res) {
          console.log(res);
        },
        error: function (err) {
          console.error(err);
        }
      });
    }
  </script>
</body>
</html>